<template>
  <div id="app">

    <div id="pad-w">
        <div class="h-10"></div>
        <van-row type="flex" gutter="10"  justify="space-between">
          <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onJiazai" :immediate-check="immediate">
            <van-col span="24" v-for="(list, index) in list" :key="index" class="span12"  @click="tiao(list.id)">
              <img v-lazy="list.picurl"  />
              <van-cell size="large">
                <!-- 使用 title 插槽来自定义标题 -->
                <template #title>
                  {{list.title}}
                </template>
                <template #label>
                  <van-icon name="underway-o" />&nbsp;{{list.time}}
                </template>
              </van-cell>
            </van-col>
          </van-list>
        </van-row>
    </div>
    <div class="h-50"></div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      list: [],
      immediate:false,
      loading: false,
      finished: false,
      page: 1,//请求第几页
      total: 0,//总共的数据条数
    }
  },
  components: {
  },
  created:function () {
      this.$emit('footer', true);
  },

  mounted () {
    this.recordapi();
  },
	activated() {
		if (this.$route.meta.keepAlive) {
			this.$emit('footer', true);
		}
	},
  	methods: {
      tiao(e){
        this.$router.push('Newscont?id='+e)
        console.log(e);
      },
      recordapi(){
          var that = this;
          var userid = that.$cookieStore.getCookie('userid');
          that.$api.post("/Index/newslist",{'page':this.page}).then(res => {
            console.log(res);
            let rows = res.list.data; //请求返回当页的列表
            // // console.log(that.page);
            console.log(rows)
             that.loading  = false;
             that.pageSize = res.list.per_page;
             that.total    = res.list.total;
             if (rows == null || rows.length === 0) {
               // 加载结束
               that.finished = true;
               return;
             }
            // 将新数据与老数据进行合并
             that.list = that.list.concat(rows);
            // //如果列表数据条数>=总条数，不再触发滚动加载
            if(that.list.length >= that.total){
               that.finished = true;
            }
          });
      },
      // 加载
      onJiazai:function(){
        var that = this;
        that.page++;
        console.log(that.page)
        that.recordapi()
      },
    }
}
</script>
